import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_animation/home_page.dart';
import 'package:flutter_animation/utils/constant.dart';

class LoginPage extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _LoginPageState();
  }
}


class _LoginPageState extends State<LoginPage> {

  TextEditingController phoneController = TextEditingController();
  TextEditingController pswController = TextEditingController();


  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        key: Key(Constant.loginTitleKey),
        title: Text(Constant.loginTitle),
      ),
      body: GestureDetector(
        behavior: HitTestBehavior.translucent,
        onTap: () async {
          FocusScope.of(context).requestFocus(FocusNode());
        },
        child: SingleChildScrollView(
          child: Column(
            children: <Widget>[
              SizedBox(height: 64.5,),
              Container(
                child: Row(
                  children: <Widget>[
                    SizedBox(width: 42.5,),
                    Text('账号登录', style: TextStyle(
                      color: Color(0xFFCA561D),
                      fontSize: 21,
                    ),),
                  ],
                ),
              ),
              SizedBox(height: 70,),
              Container(
                child: Row(
                  children: <Widget>[
                    SizedBox(width: 42.5,),
                    Container(
                      width: 290,
                      height: 33,
                      child: Column(
                        children: <Widget>[
                          Container(
                            height: 32,
//                            color: Colors.red,
                            alignment: Alignment.center,
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.center,
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: <Widget>[
                                Image.asset(
                                  'assets/images/ky_login_icon_phone.png',
                                  width: 12, height: 22,),
//                                SizedBox(width: 7.5.px,),
                                ConstrainedBox(
                                  constraints: BoxConstraints(
                                    maxWidth: 270,
                                    maxHeight: 32,
                                  ),
                                  child: TextField(
                                    key: Key(Constant.loginPhoneTFKey),
                                    inputFormatters: [
                                      //只允许输入数字*
                                      FilteringTextInputFormatter(
                                          RegExp("[0-9]"), allow: true),
                                      LengthLimitingTextInputFormatter(20)
                                    ],
                                    controller: phoneController,
                                    keyboardType: TextInputType.text,
                                    // 光标颜色
                                    cursorColor: Color(0xFF191F25),
                                    style: TextStyle(
                                      color: Color(0xFF191F25),
                                      fontSize: 14,
                                    ),
                                    maxLines: 1,
                                    decoration: InputDecoration(
                                      hintText: '请输入账号',
                                      hintStyle: TextStyle(
                                          color: Color(0xFFD2D2D2),
                                          fontSize: 14),
                                      border: OutlineInputBorder(
                                          borderSide: BorderSide.none),
                                    ),
                                    textAlignVertical: TextAlignVertical.bottom,
                                  ),
                                ),

                              ],
                            ),
                          ),
                          Container(
                            height: 1,
                            color: Color(0xFFEDEDED),
                          ),
                        ],
                      ),
                    ),
                  ],

                ),

              ),
              SizedBox(height: 50,),
              //密码
              Container(
                child: Row(
                  children: <Widget>[
                    SizedBox(width: 42.5,),
                    Container(
                      width: 290,
                      height: 33,
                      child: Column(
                        children: <Widget>[
                          Container(
                            height: 32,
                            child: Row(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: <Widget>[
                                Image.asset(
                                  'assets/images/ky_login_icon_psw.png',
                                  width: 12, height: 16.5,),
                                ConstrainedBox(
                                  constraints: BoxConstraints(
                                    maxWidth: 270,
                                    maxHeight: 32,
                                  ),
                                  child: TextField(
                                    key: Key(Constant.loginPswTFKey),
                                    controller: pswController,
                                    keyboardType: TextInputType.text,
                                    // 光标颜色
                                    cursorColor: Color(0xFF191F25),
                                    style: TextStyle(
                                      color: Color(0xFF191F25),
                                      fontSize: 14,
                                    ),
                                    maxLines: 1,
                                    obscureText: true,
                                    decoration: InputDecoration(
                                      hintText: '请输入密码',
                                      hintStyle: TextStyle(
                                          color: Color(0xFFD2D2D2),
                                          fontSize: 14),
                                      border: OutlineInputBorder(
                                          borderSide: BorderSide.none),
                                    ),
                                    textAlignVertical: TextAlignVertical.bottom,
                                  ),
                                ),
                              ],
                            ),
                          ),
                          Container(
                            height: 1,
                            color: Color(0xFFEDEDED),
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
              ),
              SizedBox(height: 90,),
              TextButton(
                key: Key(Constant.loginButtonKey),
                onPressed: () {
                  login();
                },
                child: Container(
                  width: 290,
                  height: 40,
                  alignment: Alignment.center,
                  decoration: BoxDecoration(
                    color: Color(0xFFCA561D),
                    borderRadius: BorderRadius.all(Radius.circular(20)),
                  ),
                  child: Text(
                    '登录', style: TextStyle(color: Colors.white, fontSize: 15,),
                    textAlign: TextAlign.center,),
                ),
              ),

            ],
          ),
        ),
      ),
    );
  }

  void login() async {
    print('login button clicked');
    Navigator.of(context).pushReplacement(new MaterialPageRoute(builder: (context){
      return new HomePage();
    },settings: RouteSettings(name: Constant.homeTitle)));
  }


}